package pers.qianyu.month_202012.date_20201220;

/**
 * 645. 错误的集合
 * https://leetcode-cn.com/problems/set-mismatch/
 *
 * @author mizzle rain
 * @date 2020-12-20 17:36
 */
public class FindErrorNums {
    public int[] findErrorNums(int[] nums) {
        int[] res = new int[2];
        for (int i = 0; i < nums.length; i++) {
            int index = Math.abs(nums[i]) - 1;
            if (nums[index] > 0) {
                nums[index] = -nums[index];
            } else {
                res[0] = Math.abs(nums[i]);
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > 0) {
                res[1] = i + 1;
            }
        }
        return res;
    }
}
